package com.elysia.newsservice.controller;

import com.elysia.newsservice.domain.dto.CarouselDTO;
import com.elysia.newsservice.domain.vo.CarouselVO;
import com.elysia.newsservice.result.Result;
import com.elysia.newsservice.service.impl.ICarouselServiceImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 轮播图控制层
 */
@RestController
@RequestMapping("/carousel")
@RequiredArgsConstructor
@Slf4j
public class CarouselController {
    private final ICarouselServiceImpl carouselService;
    /**
     * 添加轮播图
     * @param carouselDTO 添加的轮播图信息
     * @return 添加成功后的轮播图信息
     */
    @PostMapping
    public Result<CarouselVO> addCarousel(@RequestBody CarouselDTO carouselDTO) {
        log.info("添加轮播图{}", carouselDTO);
        return carouselService.addCarousel(carouselDTO);
    }
    /**
     * 获取全部轮播图
     * @return 全部轮播图列表
     */
    @GetMapping
    public Result<List<CarouselVO>> getAllCarousel() {
        log.info("获取全部轮播图");
        return carouselService.getAllCarousel();
    }
    /**
     * 删除轮播图
     * @param id 轮播图id
     * @return 删除结果
     */
    @DeleteMapping("/{id}")
    public Result<String> deleteCarousel(@PathVariable Long id) {
        log.info("删除轮播图: {}", id);
        return carouselService.deleteCarousel(id);
    }
    /**
     * 修改轮播图
     * @param carouselDTO 修改的轮播图信息
     * @return 修改后的轮播图信息
     */
    @PutMapping("/{id}")
    public Result<CarouselVO> updateCarousel(@PathVariable Long id, @RequestBody CarouselDTO carouselDTO) {
        log.info("更新轮播图{}: {}", id, carouselDTO);
        return carouselService.updateCarousel(id, carouselDTO);
    }
}
